<template>
    <div class="fund-account">
        <TopTitleExit title="Fund Account" :exit="routerExit"></TopTitleExit>
        <div class="main">
            <div class="top-grid">
                <div class="item">
                    <div class="k">Available</div>
                    <div class="v">${{ userInfo.balance }}</div>
                </div>
                <div class="item">
                    <div class="k">Frozon</div>
                    <div class="v">${{ userInfo.freeze }}</div>
                </div>
                <div class="item">
                    <div class="k">Total</div>
                    <div class="v">${{ (parseFloat(userInfo.balance) + parseFloat(userInfo.freeze)).toFixed(2) }}</div>
                </div>
            </div>
            <div class="list">
                <div class="item" v-for="item in flowList" :key="item.id">
                    <div class="top">
                        <div class="date">{{ format_utc5(item.createTime * 1000) }}</div>
                        <div class="status" :style="`color: ${ parseFloat(item.afterBalance) > parseFloat(item.beforeBalance) ? 'var(--positive-number-color)' : 'var(--negative-number-color)' }`">{{ parseFloat(item.afterFreeze) > parseFloat(item.beforeFreeze) ? 'Outcome' : 'Income' }}</div>
                    </div>
                    <div class="center">
                        <div class="grid">
                            <div class="val">
                                <div class="k">Amt.</div>
                                <div class="v">${{ item.amount }}</div>
                            </div>
                            <div class="val">
                                <div class="k">Frozon</div>
                                <!-- <div class="v">$0.00</div> -->
                                <!-- <div class="v">${{ (parseFloat(item.afterFreeze) - parseFloat(item.beforeFreeze)).toFixed(2) }}</div> -->
                                <div class="v">${{ item.afterFreeze }}</div>
                            </div>
                            <div class="val">
                                <div class="k">Available</div>
                                <div class="v">${{ item.afterBalance }}</div>
                            </div>
                        </div>
                    </div>
                    <div class="bottom">
                        <div class="val">
                            <div class="k">Type</div>
                            <div class="v">{{ flowDetail[item.detail] }}</div>
                        </div>
                        <div class="val">
                            <div class="k">Remark</div>
                            <div class="v">--</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script setup>
import TopTitleExit from '@/components/common/TopTitleExit.vue';
import { routerExit } from '@/utils/jump';
import { depositService, flowList } from '@/service/deposit';
import { onMounted } from 'vue';
import { loading } from '@/service/status';
import { format_utc5 } from '@/utils/time';
import { userInfo } from '@/service/user';

const flowDetail = {
    0: '后台上分',
    1: '后台充值',
    2: '后台下分',
    3: '后台提现',
    4: '后台冻结',
    5: '后台解冻',
    6: '用户充值',
    7: '提现冻结',
    8: '提现失败',
    9: '提现成功',
    10: '提现取消',
    11: '市价开仓扣除',
    12: '限价开仓冻结',
    13: '限价开仓取消',
    14: '限价开仓扣除',
    15: '股票平仓',
    16: 'IPO认购支出',
    17: '平仓解冻',
    18: '配资通过',
    19: '配资还款'
};

onMounted(async () => {
    loading.value = true;
    await depositService.getFlowList();
    loading.value = false;
});
</script>

<style scoped lang="less">
.fund-account {
    width: 100vw;
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;

    .main {
        box-sizing: border-box;
        width: 100%;
        flex: 1;
        overflow-y: auto;
        padding: 3vw;

        .top-grid {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            grid-gap: 2vw;

            .item {
                padding: 1vw 0 5vw;
                text-align: center;

                .k {
                    font-size: 4vw;
                    font-weight: 500;
                    color: var(--active-color);
                }

                .v {
                    font-size: 3.5vw;
                }
            }
        }

        .list {
            display: flex;
            flex-direction: column;
            gap: 3vw;

            .item {
                box-sizing: border-box;
                width: 100%;
                padding: 3vw;
                border-radius: 2vw;
                box-shadow: 0 0 3vw rgba(0, 0, 0, 0.1);
                display: flex;
                flex-direction: column;
                gap: 3vw;

                .top {
                    display: flex;
                    justify-content: space-between;
                    align-items: center;

                    .date {
                        font-size: 3.3vw;
                        color: var(--text-color);
                    }

                    .status {
                        font-size: 3.5vw;
                        font-weight: 500;
                        color: var(--positive-number-color);
                    }
                }

                .center {
                    .grid {
                        display: grid;
                        grid-template-columns: repeat(3, 1fr);
                        grid-gap: 2vw;

                        .val {
                            text-align: center;

                            &:first-child {
                                text-align: left;
                            }

                            &:last-child {
                                text-align: right;
                            }

                            .k {
                                font-size: 3.5vw;
                                font-weight: 500;
                            }

                            .v {
                                font-size: 3vw;
                            }
                        }
                    }
                }

                .bottom {
                    display: flex;
                    justify-content: space-between;

                    .val {
                        &:first-child {
                            text-align: left;
                        }

                        &:last-child {
                            text-align: right;
                        }

                        .k {
                            font-size: 3.5vw;
                            font-weight: 500;
                        }

                        .v {
                            font-size: 3vw;
                        }
                    }
                }
            }
        }
    }
}
</style>